﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace P1
{
    class Program
    {
        static void Main(string[] args)
        {
            Person person = new Person();
            Computer computer = new Computer();
            int count = 0;
            int score1 = 0;
            int score2 = 0;
            Console.WriteLine("----------欢迎进入游戏世界----------");
            Console.WriteLine("*************************************");
            Console.WriteLine("**************猜拳，开始*************");
            Console.WriteLine("*************************************");
            a: Console.WriteLine("出拳规则：1.剪刀2.石头3.布");
            Console.WriteLine("请选择对方角色<1：刘备2：孙权3：曹操>");
            int key = int.Parse(Console.ReadLine());
            if (key == 1)
            {
                computer.Name = "刘备";
            }
            if (key == 2)
            {
                computer.Name = "孙权";
            }
            if (key == 3)
            {
                computer.Name = "曹操";
            }
            Console.WriteLine("请输入您的姓名：");
            person.Name = Console.ReadLine();
            Console.WriteLine($"{person.Name} vs {computer.Name}对战");
             Console.WriteLine("开始游戏吗？<y/n>");
            string ks = Console.ReadLine();
            while (Xh(ks))
            {
                if (ks == "y")
                {
                    int per = person.Per();
                    int com = computer.Com();

                    if (per == 1 && com == 1)
                    {
                        Console.WriteLine("和局，真衰！嘿嘿，等着瞧吧！");
                    }
                    else if (per == 1 && com == 2)
                    {
                        Console.WriteLine($"笨蛋，{person.Name}输了");
                        score2++;
                    }
                    
                    else if (per == 1 && com == 3)
                    {
                        Console.WriteLine($"恭喜，{person.Name}赢了");
                        score1++;
                    }
                    else if (per == 2 && com == 1)
                    {
                        Console.WriteLine($"恭喜，{person.Name}赢了");
                        score1++;
                    }
                    else if (per == 2 && com == 2)
                    {
                        Console.WriteLine("和局，真衰！嘿嘿，等着瞧吧！");
                    }
                    else if (per == 2 && com == 3)
                    {
                        Console.WriteLine($"笨蛋，{person.Name}输了");
                        score2++;
                    }
                    else if (per == 3 && com == 1)
                    {
                        Console.WriteLine($"笨蛋，{person.Name}输了");
                        score2++;
                    }
                    else if (per == 3 && com == 2)
                    {
                        Console.WriteLine($"恭喜，{person.Name}赢了");
                        score1++;
                    }
                    else if (per == 3 && com == 3)
                    {
                        Console.WriteLine("和局，真衰！嘿嘿，等着瞧吧！");
                    }
                    Console.WriteLine("是否开始下一轮？<y/n>");
                    ks = Console.ReadLine();
                    Xh(ks);
                    count++;
                    if (ks=="n")
                    {
                        Console.WriteLine("*************************************");
                        Console.WriteLine($"{computer.Name} vs {person.Name}对战");
                        Console.WriteLine($"对战次数： {count}");
                        Console.WriteLine();
                        Console.WriteLine("姓名"+"\t"+"得分");
                        Console.WriteLine($"{person.Name}\t{score1}");
                        Console.WriteLine($"{computer.Name}\t{score2}");
                        if (score1>score2)
                        {
                            Console.WriteLine($"结果：{person.Name}赢，{computer.Name}笨蛋");
                        }
                        else if (score1 < score2)
                        {
                            Console.WriteLine($"结果：{computer.Name}赢，{person.Name}笨蛋");
                        }
                        else if (score1 == score2)
                        {
                            Console.WriteLine($"恭喜你们！{computer.Name}和{person.Name}平局！");
                        }
                        Console.WriteLine("要开始下一局吗？<y/n>");
                        string sf = Console.ReadLine();
                        switch (sf) {
                            case "y":
                                goto a;
                            case "n":
                                Console.WriteLine("系统退出！！！！！");
                                break;
                        }
                    }
                }
            }
        }

        private static bool Xh(string ks)
        {
            bool b;
            if (ks == "y")
            { b = true; }
            else { b = false; }
            return b;
        }
    }
}
    

